﻿

namespace Huirui.Cavan.Domain.MainBoundedContext.SystemModule
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Huirui.Cavan.Core.Persistent;
    using Huirui.Cavan.Domain.MainBoundedContext.SearchModule;
    using Huirui.Cavan.Core.MyLinq;
    using Huirui.Cavan.Core.Extension;

    public class RoleSpecification : ISpecification<Role, RoleSearch>
    {
        public RoleSpecification()
        {
            this.SearchParams = new RoleSearch();
        }

        public RoleSearch SearchParams
        {
            get;
            set;
        }

        public System.Linq.Expressions.Expression<Func<Role, bool>> Expression
        {
            get
            {
                IQueryBuilder<Role> queryBuilder = QueryBuilder.Create<Role>();

                if (null != SearchParams)
                {
                    if (SearchParams.Name.IsNotEmpty())
                    {
                        queryBuilder = queryBuilder.Equals(r => r.Name, SearchParams.Name);
                    }
                }

                return queryBuilder.Expression.Expand();
            }
        }
    }
}
